 
<template >
      <DropBox>
    <div id="breakon-drop-article-menu" > 
    <!-- <a-button draggable="true" shape="circle" type="primary"> 目 </a-button>
    按住拖拽，双击展开 -->
     <a-button @click="treeShow=!treeShow"    shape="circle" type="primary"  >
    按钮 
  </a-button>  
    <a-tree
      v-show="treeShow"
      :load-data="onLoadData"
      class="draggable-tree"
      :default-expanded-keys="expandedKeys"
      draggable
      :tree-data="gData"
      @dragenter="onDragEnter"
      @drop="onDrop"
    />
  </div>
   </DropBox>
</template>

<script>
import DropBox from "@/components/DropBox"
const x = 3;
const y = 2;
const z = 1;
const gData = [];

const generateData = (_level, _preKey, _tns) => {
  const preKey = _preKey || "0";
  const tns = _tns || gData;

  const children = [];
  for (let i = 0; i < x; i++) {
    const key = `${preKey}-${i}`;
    tns.push({ title: key, key });
    if (i < y) {
      children.push(key);
    }
  }
  if (_level < 0) {
    return tns;
  }
  const level = _level - 1;
  children.forEach((key, index) => {
    tns[index].children = [];
    return generateData(level, key, tns[index].children);
  });
};
generateData(z);
export default {
  data() {
    return {
      gData,
      expandedKeys: ["0-0", "0-0-0", "0-0-0-0"],
      treeShow:true,
    };
  },
  components:{
      DropBox,
  },
  methods: {
    onDragEnter(info) {
      console.log(info);
      // expandedKeys 需要受控时设置
      // this.expandedKeys = info.expandedKeys
    },
    onLoadData(treeNode) {
      return new Promise((resolve) => {
        if (treeNode.dataRef.children) {
          resolve();
          return;
        }
        setTimeout(() => {
          treeNode.dataRef.children = [
            { title: "Child Node", key: `${treeNode.eventKey}-0` },
            { title: "Child Node", key: `${treeNode.eventKey}-1` },
          ];
          this.gData = [...this.gData];
          resolve();
        }, 1000);
      });
    },
    onDrop(info) {
      console.log(info);
      const dropKey = info.node.eventKey;
      const dragKey = info.dragNode.eventKey;
      const dropPos = info.node.pos.split("-");
      const dropPosition =
        info.dropPosition - Number(dropPos[dropPos.length - 1]);
      const loop = (data, key, callback) => {
        data.forEach((item, index, arr) => {
          if (item.key === key) {
            return callback(item, index, arr);
          }
          if (item.children) {
            return loop(item.children, key, callback);
          }
        });
      };
      const data = [...this.gData];

      // Find dragObject
      let dragObj;
      loop(data, dragKey, (item, index, arr) => {
        arr.splice(index, 1);
        dragObj = item;
      });
      if (!info.dropToGap) {
        // Drop on the content
        loop(data, dropKey, (item) => {
          item.children = item.children || [];
          // where to insert 示例添加到尾部，可以是随意位置
          item.children.push(dragObj);
        });
      } else if (
        (info.node.children || []).length > 0 && // Has children
        info.node.expanded && // Is expanded
        dropPosition === 1 // On the bottom gap
      ) {
        loop(data, dropKey, (item) => {
          item.children = item.children || [];
          // where to insert 示例添加到尾部，可以是随意位置
          item.children.unshift(dragObj);
        });
      } else {
        let ar;
        let i;
        loop(data, dropKey, (item, index, arr) => {
          ar = arr;
          i = index;
        });
        if (dropPosition === -1) {
          ar.splice(i, 0, dragObj);
        } else {
          ar.splice(i + 1, 0, dragObj);
        }
      }
      this.gData = data;
    },
  },
};
</script>

<style lang="scss" scoped>
#breakon-drop-article-menu{
max-width: 212px;
padding: 5px;
 box-shadow: 0 0px 26px rgba(0, 0, 0, 0.1);
background:#fff;
}

[draggable=true] {
    cursor: move;
}

</style>